/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.editparts;

import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.editpolicies.DirectEditPolicy;
import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.ReconnectRequest;

import edu.pku.sei.modeler.editpolicies.UMLDiagramGraphicalNodeEditPolicy;
import edu.pku.sei.modeler.figures.ActivityFinalNodeFigure;
import edu.pku.sei.modeler.model.core.MetaElement;
import edu.pku.sei.modeler.model.structure.MetaLink;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.structure.MetaShapeElement;
import edu.pku.sei.modeler.model.uml.BasicActivities.ActivityFinalNode;
import edu.pku.sei.modeler.model.uml.BasicActivities.ControlFlow;
import edu.pku.sei.modeler.uml.commands.UMLConnectionCreateCommand;


/**
 * @generated
 *
 */
public class ActivityFinalNodeEditpart extends AbstractUMLNodeEditPart 
{
	public ActivityFinalNodeEditpart (MetaShapeElement model) {
		super(model);
	}
	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
	 */
	protected IFigure createFigure() {
		Label header = new Label("GeneratedShape");
		ActivityFinalNodeFigure figure = new ActivityFinalNodeFigure();
		figure.add(header);
		return figure;
	}

	protected DirectEditPolicy createDirectEditPolicy() {
		return null;
	}
	
	@Override
	protected IFigure getDirectEditFigure() {
		Label header = (Label)getFigure();
		return header;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
	 */
	protected void createEditPolicies() {
		super.createEditPolicies();
		
		installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new UMLDiagramGraphicalNodeEditPolicy(this.getNode().getDiagram().getType()));
	}

	protected void handlePropertyChanged(PropertyChangeEvent event) {
		String propertyName = event.getPropertyName();
		super.handlePropertyChanged(event);
	}
	
	private ActivityFinalNode getActivityFinalNode() {
		return (ActivityFinalNode)((MetaNode)getModel()).getModelElement();
	}
	
	protected void refreshVisuals() {
		super.refreshVisuals();
		MetaNode modelEle = getNode();
		
		if (modelEle.getWidth()!=20 || modelEle.getHeight()!=20) {
			modelEle.setWidth(20);
			modelEle.setHeight(20);
		} 
	}
}
